home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / gamesrc / fring11 / pic_make.pas < prev    next >
Pascal/Delphi Source File  |  1992-12-17  |  10KB  |  438 lines

  1. {
  2. ***************************************************************************
  3. * PIC_MAKER - for                                                         *
  4. * FRINGDUS - The Game. (1/12/92)                                          *
  5. *                                                                         *
  6. *  By Jason Nunn (JsNO BAR----NUNN)                                       *
  7. *                                                                         *
  8. *  Email: nunn@pandanus.cs.ntu.edu.au                                     *
  9. *                                                                         *
  10. *  This code is freeware.                                                 *
  11. *                                                                         *
  12. * Description: Allows you to make 30*30 256 colour sprites.               *
  13. *                                                                         *
  14. ***************************************************************************
  15. }
  16. program pic_maker;
  17.  
  18. uses
  19.   crt;
  20.  
  21. const
  22.   norm_vid  = 3;
  23.   hires_vid = 19;
  24.   video_mem = 40960;
  25.  
  26.   nullchar               = #0;
  27.   enter                  = #13;
  28.   back_space             = #8;
  29.   bell                   = #7;
  30.   uparrow                = #0#72;
  31.   leftarrow              = #0#75;
  32.   rightarrow             = #0#77;
  33.   downarrow              = #0#80;
  34.   esc                    = #27;
  35.   space                  = ' ';
  36.  
  37.  
  38. type
  39.   pic_attrib = record
  40.                  colour : byte;
  41.                end;
  42.   pic_file_attrib = file of pic_attrib;
  43.  
  44. var
  45.   pic_file  : pic_file_attrib;
  46.   pic       : pic_attrib;
  47.   ch        : string[2];
  48.   cx        : integer;
  49.   cy        : integer;
  50.   cxl       : integer;
  51.   cyl       : integer;
  52.   p_colour  : word;
  53.  
  54. {
  55. ***************************************************************************
  56. *                                                                         *
  57. * Utility functions                                                       *
  58. *                                                                         *
  59. ***************************************************************************
  60. }
  61.  
  62.  
  63. procedure videooff; assembler;
  64. asm
  65.   mov  al,norm_vid  {normal default value}
  66.   mov  ah,0
  67.   int  16 {Video services interrupt, for more}
  68. end;      {information, have a look at your system manuals}
  69.  
  70. {I couldn't get my graphic libraries to work, to put it in Hires, so
  71. I made the routines myself}
  72.  
  73.  
  74. procedure videoon; assembler;
  75. asm
  76.   mov  al,hires_vid  {320*200   256 colour mode}
  77.   mov  ah,0
  78.   int  16
  79. end;
  80.  
  81.  
  82.  
  83.  
  84. {Puts a byte on to the video memory at location X,Y, the byte value is
  85. the COLOUR}
  86.  
  87. procedure write_byte(colour : byte; ggx, ggy : word); assembler;
  88. asm
  89.   mov   bx,video_mem
  90.   mov   es,bx
  91.  
  92.   mov   ax,ggy
  93.   mov   bx,320
  94.   mul   bx
  95.  
  96.   add   ax,ggx
  97.   mov   bx,ax
  98.   mov   al,colour
  99.   mov   es:[bx],al
  100. end;
  101.  
  102.  
  103.  
  104. {Here we read a byte value at position X,Y}
  105.  
  106. function get_colour(ggx, ggy : word) : byte; assembler;
  107. asm
  108.   mov   bx,video_mem
  109.   mov   es,bx
  110.  
  111.   mov   ax,ggy
  112.   mov   bx,320
  113.   mul   bx
  114.  
  115.   add   ax,ggx
  116.   mov   bx,ax
  117.  
  118.   mov   al, es:[bx]  {AL is returned, hence: get_colour := AL}
  119. end;
  120.  
  121.  
  122.  
  123.  
  124. {sets 8x6 block of bytes in video memory a certain value(colour) }
  125.  
  126. procedure write_6_8_block(colour : byte; x, y : word); assembler;
  127. var
  128.   store_y : word;
  129.  
  130. asm
  131.   mov   bx,video_mem
  132.   mov   es,bx
  133.   mov   ax,0
  134.   mov   store_y, ax
  135.   dec   y
  136. @@bloc_loop:
  137.   add   y,1
  138.   mov   ax,y
  139.   mov   bx,320
  140.   mul   bx
  141.  
  142.   add   ax, x
  143.   mov   di, ax
  144.   mov   al, colour
  145.   mov   cx, 7
  146.   cld
  147.   rep   stosb
  148.  
  149.   inc   store_y
  150.   cmp   store_y,5
  151.   jne   @@bloc_loop
  152. end;
  153.  
  154.  
  155. {This is a highlight bar that is intended for the block colours, on
  156. the screen in determining that current colour that the user has selected}
  157.  
  158. procedure hl_6_8_block(colour : byte; x, y : word); assembler;
  159. asm
  160.   mov   bx,video_mem
  161.   mov   es,bx
  162.  
  163.   mov   ax,y
  164.   mov   bx,320
  165.   mul   bx
  166.  
  167.   add   ax, x
  168.   mov   di, ax
  169.   mov   al, colour
  170.   mov   cx, 7
  171.   cld
  172.   rep   stosb
  173. end;
  174.  
  175. {sets 3x3 block of bytes in video memory a certain value(colour) }
  176.  
  177. procedure write_3_3_block(colour : byte; x, y : word); assembler;
  178. var
  179.   store_y : word;
  180.  
  181. asm
  182.   mov   bx,video_mem
  183.   mov   es,bx
  184.   mov   ax,0
  185.   mov   store_y, ax
  186.   dec   y
  187. @@bloc_loop:
  188.   add   y,1
  189.   mov   ax,y
  190.   mov   bx,320
  191.   mul   bx
  192.  
  193.   add   ax, x
  194.   mov   di, ax
  195.   mov   al, colour
  196.   mov   cx, 3
  197.   cld
  198.   rep   stosb
  199.  
  200.   inc   store_y
  201.   cmp   store_y,3
  202.   jne   @@bloc_loop
  203. end;
  204.  
  205.  
  206.  
  207. {This routine clears the screen}
  208.  
  209. procedure clr(color : byte); assembler;
  210. asm
  211.   mov   bx,video_mem
  212.   mov   es,bx
  213.   mov   al,color
  214.   mov   di, 0
  215.   mov   si, di
  216.   mov   cx,64000
  217.  
  218.   cld
  219.   rep   stosb
  220. end;
  221.  
  222. {
  223. ***************************************************************************
  224. *                                                                         *
  225. ***************************************************************************
  226. }
  227. procedure base_screen;
  228. var
  229.   x      : word;
  230.   y      : word;
  231.   colour : word;
  232. begin
  233.   colour := 0;
  234.   for y := 0 to 7 do
  235.   begin
  236.     for x := 0 to 38 do
  237.     begin
  238.       if colour <= 255 then
  239.       begin
  240.         write_6_8_block(colour, x * 8, y * 6); {writes the blocks of colour}
  241.       end;
  242.  
  243.       if (p_colour = (x + (y * 39))) then
  244.       begin
  245.         hl_6_8_block(15, x * 8, (y * 6) + 5);
  246.       end;
  247.       colour := colour + 1;
  248.     end;
  249.   end;
  250.   for x := 218 to 311 do
  251.     write_byte(15, x, 98);
  252.  
  253.   for x := 98 to 191 do
  254.     write_byte(15, 218, x);   {writes the pretty border, for sprite editing area}
  255.  
  256.   for x := 218 to 311 do
  257.     write_byte(15, x, 191);
  258.  
  259.   for x := 98 to 191 do
  260.     write_byte(15, 311, x);
  261.  
  262.   for x := 0 to 33 do
  263.   begin
  264.     write_byte(15, x + 48, 98); {writes another pretty border, (for the sprite area)}
  265.     write_byte(15, 48, 98 + x);
  266.     write_byte(15, 81, 131 - x);
  267.     write_byte(15, 81 - x, 131);
  268.   end;
  269. end;
  270.  
  271. {
  272. ***************************************************************************
  273. *                                                                         *
  274. * The code is obvious                                                     *
  275. *                                                                         *
  276. ***************************************************************************
  277. }
  278. procedure paint_pic;
  279. var
  280.   x      : word;
  281.   y      : word;
  282. begin
  283.   base_screen;
  284.   cx := 0;
  285.   cy := 0;
  286.   cxl := 0;
  287.   cyl := 0;
  288.   ch := #0;
  289.   repeat
  290.  
  291.     if ch = downarrow then
  292.       cy := cy + 1
  293.     else if ch = uparrow then
  294.       cy := cy - 1
  295.     else if ch = leftarrow then
  296.       cx := cx - 1
  297.     else if ch = rightarrow then
  298.       cx := cx + 1
  299.     else if (ch = '+') or (ch = '-') or (ch = '/') or (ch = '*') then
  300.     begin
  301.       for y := 0 to 7 do
  302.       begin
  303.         for x := 0 to 38 do
  304.         begin
  305.           if (p_colour = (x + (y * 39))) then
  306.           begin
  307.             hl_6_8_block(0, x * 8, (y * 6) + 5);
  308.           end;
  309.         end;
  310.       end;
  311.  
  312.       if ch = '+' then
  313.         p_colour := p_colour + 1
  314.       else if ch = '-' then
  315.         p_colour := p_colour - 1
  316.       else if ch = '/' then
  317.         p_colour := p_colour - 10
  318.       else if ch = '*' then
  319.         p_colour := p_colour + 10;
  320.  
  321.       if p_colour < 0 then p_colour := 0;
  322.       if p_colour > 255 then p_colour := 255;
  323.  
  324.       for y := 0 to 7 do
  325.       begin
  326.         for x := 0 to 38 do
  327.         begin
  328.           if (p_colour = (x + (y * 39))) then
  329.           begin
  330.             hl_6_8_block(15, x * 8, (y * 6) + 5);
  331.           end;
  332.         end;
  333.       end;
  334.     end
  335.     else if ch = '`' then
  336.     begin
  337.       for y := 0 to 29 do
  338.         for x := 0 to 29 do
  339.         begin
  340.           write_byte(p_colour, x + 50, y + 100);
  341.           write_3_3_block(p_colour, 220 + (x * 3), 100 + (y * 3));
  342.         end;
  343.       cxl := cx;
  344.       cyl := cy;
  345.     end;
  346.  
  347.     if ch = 's' then
  348.     begin
  349.       rewrite(pic_file);
  350.       for cy := 0 to 29 do
  351.         for cx := 0 to 29 do
  352.         begin
  353.           pic.colour := get_colour(cx + 50, cy + 100);
  354.           write(pic_file, pic);
  355.         end;
  356.     end;
  357.     if ch = 'f' then
  358.     begin
  359.       rewrite(pic_file);
  360.       for cy := 29 downto 0 do
  361.         for cx := 0 to 29 do
  362.         begin
  363.           pic.colour := get_colour(cx + 50, cy + 100);
  364.           write(pic_file, pic);
  365.         end;
  366.     end;
  367.     if ch = 't' then
  368.     begin
  369.       rewrite(pic_file);
  370.       for cy := 0 to 29 do
  371.         for cx := 29 downto 0 do
  372.         begin
  373.           pic.colour := get_colour(cx + 50, cy + 100);
  374.           write(pic_file, pic);
  375.         end;
  376.     end;
  377.  
  378.     if cx < 0 then cx := 0;
  379.     if cx > 29 then cx := 29;
  380.     if cy < 0 then cy := 0;
  381.     if cy > 29 then cy := 29;
  382.  
  383.     write_3_3_block(get_colour(cxl + 50, cyl + 100), 220 + (cxl * 3), 100 + (cyl * 3));
  384.     write_3_3_block(p_colour, 220 + (cx * 3), 100 + (cy * 3));
  385.     if ch = space then
  386.     begin
  387.       write_byte(p_colour, cx + 50, cy + 100);
  388.     end;
  389.  
  390.     cxl := cx;
  391.     cyl := cy;
  392.  
  393.     ch := readkey;
  394.     if ch = #0 then ch := ch + readkey;
  395.   until ch = #27;
  396. end;
  397.  
  398. {
  399. ***************************************************************************
  400. *                                                                         *
  401. * The code is obvious                                                     *
  402. *                                                                         *
  403. ***************************************************************************
  404. }
  405. begin
  406.   if (paramstr(1) <> '') and (paramstr(1) <> '-h') then
  407.   begin
  408.     p_colour := 1;
  409.     videoon;
  410.     clr(0);
  411.     assign(pic_file,paramstr(1));
  412.     {$I-}
  413.     reset(pic_file);
  414.     {$I-}
  415.     if ioresult = 0 then
  416.     begin
  417.       for cy := 0 to 29 do
  418.         for cx := 0 to 29 do
  419.         begin
  420.           read(pic_file, pic);
  421.           write_byte(pic.colour, cx + 50, cy + 100);
  422.           write_3_3_block(pic.colour, 220 + (cx * 3), 100 + (cy * 3));
  423.         end;
  424.     end;
  425.     paint_pic;
  426.     close(pic_file);
  427.     videooff;
  428.   end
  429.   else
  430.   begin
  431.     writeln;   {logo.......hey ya!, hey ya!, hey ya!}
  432.     writeln('MAP_MAK2 - By Jason Nunn - (C) 1992 - This Game is Freeware');
  433.     writeln;
  434.     writeln('Instructions: Read Manual (readme.txt)');
  435.     writeln;
  436.   end;
  437. end.
  438.